<?php
class referensi extends Model {
    //Sitem pembatan list
    function get_list($table_name="",$field_value="",$field_label="") {
        if(empty($field_value))
            $field_value = "id";
        if(empty($field_label))
            $field_label=$table_name;

        $data = $this->db->query("Select * from ".$table_name);
        return $this->create_list($data->result_array(),$field_value,$field_label);
    }

    function get_list_referensi($table_name="",$field_value="",$field_label="") {
        if(empty($field_value))
            $field_value = "id";
        if(empty($field_label))
            $field_label=$table_name;
        $table_name = "r_".$table_name;
        return $this->get_list($table_name,$field_value,$field_label);
    }
    function create_list($data,$key,$value) {
        $ret = array();
        foreach($data as $det) {
            $ret[$det[$key]] = $det[$value];
        }
        return  $ret;
    }

    //list spesifik
    function get_list_jenis_kelamin() {
        $tabel = "jenis_kelamin";
        $data = $this->db->query("Select * from r_".$tabel);
        return $this->create_list($data->result_array(),"id",$tabel);
    }
    function get_list_sekolah() {
        $tabel = "m_sekolah";
        $data = $this->db->query("Select * from ".$tabel);
        $ret = $this->create_list($data->result_array(),"id","nama_sekolah");
        return $ret;
    }
    function get_list_agama() {
        $tabel = "agama";
        $data = $this->db->query("Select * from r_".$tabel);
        return $this->create_list($data->result_array(),"id",$tabel);
    }
    function get_sekolah($sekolah_id) {
        $tabel = "m_sekolah";
        $data = $this->db->query("Select * from ".$tabel." where id=$sekolah_id");
        $ret = $data->result_array();
        return $ret[0];
    }
    function get_list_jenjang_pendidikan() {
        $tabel = "jenjang_pendidikan";
        $data = $this->db->query("Select * from r_".$tabel);
        return $this->create_list($data->result_array(),"id",$tabel);
    }
	// lainnya
	function get_id_from_sekolah_jenis_strip($strip){
		$data = $this->db->query("Select * from r_sekolah_jenis where sekolah_jenis_strip='$strip'");
		$ret = $data->result_array();
		if(isset($ret[0])){
			return $ret[0]['id'];
		}else{
			return NULL;
		}
	}

}